//
//  QJUserInfo.m
//  QuanJieShopProject
//
//  Created by apple on 2018/1/30.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "QJUserInfo.h"

@implementation QJUserInfo

#pragma mark -- 是否第一次运行
+ (BOOL)isFirstRun{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"firstStart"]) {
        //具体是否在此处做不是第一次运行的处理要根据具体的情况而定
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstStart"];
        return NO;
    }else{
        return YES;
    }
}
#pragma mark -- 是否登录
+(BOOL)isLogin{
    id currentUser = [QJUserInfo getCurrentUser];
    if (currentUser) {
        //已经登录
        return YES;
    }else{
        //未登录
        return NO;
    }
}
#pragma mark -- 注销登录
+(void)logoff{
    [[TMCache sharedCache] removeObjectForKey:CURRENTUSER];
}
#pragma mark -- 保存用户信息
+(void)saveCurrentUser:(id)dic{
    [[TMCache sharedCache] setObject:dic forKey:CURRENTUSER];
}
#pragma mark -- 获取用户的信息
+(id)getCurrentUser{
    return [[TMCache sharedCache]objectForKey:CURRENTUSER];
}
#pragma mark -- 获取用户ID
+ (NSString *)userId{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.id;
}
#pragma mark -- 获取用户的名称
+ (NSString *)userName{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.mobile;
}
#pragma mark -- 获取用户昵称
+ (NSString *)nickname{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.user_nickname;
}
#pragma mark -- 获取用户手机号
+ (NSString *)mobilePhone{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.mobile;
}
#pragma mark -- 获取用户头像
+ (NSString *)headerImageUrl{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    NSString *headerImageUrl = [NSString stringWithFormat:@"%@",model.avatar];
    
    if (headerImageUrl.length == 0) {
        return @"";
    }
    
    return  headerImageUrl;
}
#pragma mark -- 获取用户token
+ (NSString *)getToken{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.token;
}
#pragma mark -- 获取用户钱
+ (NSString *)getMoney{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.score;
}
#pragma mark -- 保存某条数据
+ (void)setObject:(id)object forKey:(NSString *)key{
    [[TMCache sharedCache] setObject:object forKey:key];
}
#pragma mark -- 获得保存的某条数据
+ (id)ObjectForKey:(NSString *)key{
    return [[TMCache sharedCache] objectForKey:key];
}
#pragma mark -- 删除保存的某条数据
+ (void)removeObjectForKey:(NSString *)key{
    [[TMCache sharedCache] removeObjectForKey:key];
}
#pragma mark -- 删除用户信息
+ (void)RemoveCurrentUser{
    [[TMCache sharedCache] removeObjectForKey:CURRENTUSER];
}
#pragma mark -- 保存启动广告图
+ (void)saveLaynchScreenImage:(UIImage *)image{
    [[TMCache sharedCache]setObject:image forKey:LAUNCHIMAGE];
}
#pragma mark -- 获得广告启动图
+ (UIImage *)getLaynchScreenImage{
    return [[TMCache sharedCache] objectForKey:LAUNCHIMAGE];
}
#pragma mark -- 获得用户类型
+ (NSString *)getUserType{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.user_type;
}

#pragma mark -- 获得用户性别
+ (NSString *)getUserSex{
    UserInfoModel *model = [QJUserInfo getCurrentUser];
    return model.sex;
}
@end
